package com.huicoo.forestmanager.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.huicoo.forestmanager.R;

/**
 * 结束巡查确认对话框
 */
public class StopPatrolConfirmDialog extends AlertDialog {
    private OnStopPatrolListener onStopPatrolListener;

    public StopPatrolConfirmDialog(Context context) {
        super(context, R.style.transDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_stop_patrol_confirm);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    public void showDialog() {
        show();

        findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        findViewById(R.id.btn_yes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onStopPatrolListener != null) {
                    onStopPatrolListener.stopPatrol(true);
                }
                dismiss();
            }
        });

        findViewById(R.id.btn_no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onStopPatrolListener != null) {
                    onStopPatrolListener.stopPatrol(false);
                }
                dismiss();
            }
        });
    }

    public interface OnStopPatrolListener {
        void stopPatrol(boolean toReportRecord);
    }

    public void setOnStopPatrolListener(OnStopPatrolListener onStopPatrolListener) {
        this.onStopPatrolListener = onStopPatrolListener;
    }
}
